package com.example.demo.controller;

import com.example.demo.data.MenuData;
import com.example.demo.util.StringUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.concurrent.ConcurrentHashMap;

@Controller
public class MennDataChangeController {
    @RequestMapping(value = "data",method ={RequestMethod.POST,RequestMethod.PUT})
    public String addOrUpdate(String key ,String value){

        if(StringUtil.isEmpty(key)||StringUtil.isEmpty(value)){
            return "请输入正确的参数";
        }

        ConcurrentHashMap<String, String> menuData = MenuData.menuData;
        menuData.put(key,value);

        return "恭喜你成功了";
    }

    @RequestMapping(value = "data",method ={RequestMethod.DELETE})
    public String del(String key){

        if(StringUtil.isEmpty(key)){
            return "请输入正确的参数";
        }

        ConcurrentHashMap<String, String> menuData = MenuData.menuData;
        menuData.remove(key);

        return "恭喜你成功了";
    }
}
